#
#    This file is part of the substandard lisp implementation of Standard Lisp
#    Copyright (C) 2011 Nicky Nickell
#
#    substandard lisp is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys
import yaml

intable = yaml.load(sys.stdin.read())

table = {}

equal = '''  equal(lisp.evaluate_string('%s'), '%s', '%s');'''
ok = '''  equal(lisp.evaluate_string('%s'), /%s/, '%s');'''
error = '''/* %s %s %s */'''  # TODO: write me
evall = '''  lisp.evaluate_string('%s');'''

for category in intable:
  table[category] = {}
  for func in intable[category]:
    if 'tests' in intable[category][func]:
      table[category][func] = []
      for test in intable[category][func]['tests']:
        test = test.strip().replace("'", "\\'")
        if test == '':
            continue
        elif ' -> ' in test:
            l = test.split(' -> ')
            table[category][func].append(equal % (l[0], l[1], test))
        elif ' -r> ' in test:
            l = test.split(' -r> ')
            table[category][func].append(error % (l[0], l[1], test))
        elif ' -m> ' in test:
            l = test.split(' -m> ')
            table[category][func].append(ok % (l[0], l[1], test))
        else:
            table[category][func].append(evall % test)

for mod in table:
    print "module('%s');\n" % mod
    for tes in table[mod]:
        print "lisp.initialize();"
        print "test('%s', function() {" % tes
        for sta in table[mod][tes]:
            print sta
        print "});\n"
